package leetcode.hot100;

import common.ListNode;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Created on 2021-01-22 。
 * 实现一个支持push pop top等操作的最小元素栈
 * @author wll 1978992154@qq.com
 */
public class MinStack {
    protected int minNode;
    protected ListNode collection;
    /** initialize your data structure here. */
    public MinStack() {
        collection = new ListNode();
    }

    public void push(int x) {
        if (x < minNode){
            minNode = x;
        }
        collection.next = new ListNode(x);
    }

    public void pop() {
        while (collection != null){
            if (collection.next.next == null){
                collection.next = null;
            }
            collection = collection.next;
        }
    }

    public int top() {
        while (collection != null){
            if (collection.next == null){
                return collection.val;
            }
            collection = collection.next;
        }
        return 0;
    }

    public int getMin() {
        return minNode;
    }
}
